using System;
using System.Timers;

namespace SDK.Scripts.Utils
{
	public class Timer
	{
		public delegate void ElaspsedEventHandle();

		public static long GetTimeStamp(bool isMS = false)
		{
			TimeSpan timeSpan = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
			if (isMS)
			{
				return Convert.ToInt64(timeSpan.TotalMilliseconds);
			}
			return Convert.ToInt64(timeSpan.TotalSeconds);
		}

		public static System.Timers.Timer SetTimeOut(ElaspsedEventHandle cb, int time)
		{
			System.Timers.Timer timer = new System.Timers.Timer();
			timer.AutoReset = false;
			timer.Enabled = true;
			timer.Interval = time;
			timer.Elapsed += delegate
			{
				if (cb != null)
				{
					cb();
					cb = null;
				}
			};
			return timer;
		}

		public static void ClearTimeOut(System.Timers.Timer timer)
		{
			if (timer != null)
			{
				timer.Stop();
				timer.Close();
			}
		}
	}
}
